/* eslint valid-jsdoc: "off" */

'use strict';

/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  /**
   * built-in config
   * @type {Egg.EggAppConfig}
   **/
  const config = exports = {};

  // use for cookie sign key, should change to your own and keep security
  config.keys = appInfo.name + '_1574410884670_2321';

  // add your user config here
  const userConfig = {
    // myAppName: 'egg',
  };

  // 上传
  config.mulipart = {
    mode: 'stream',
    whitelist: [
      '.jpg',
      '.jpeg',
      '.png',
      '.gif',
      '.zip',
      '.gz',
      '.tgz',
      '.gzip',
      '.mp3',
      '.mp4',
      '.avi',
    ],
  };

  // add your middleware config here
  config.middleware = [];

  // mysql
  config.sequelize = {
    dialect: 'mysql',
    host: '127.0.0.1',
    port: 3306,
    database: 'qcms',
    username: 'root',
    password: 'root',
    timezone: '+08:00',
    dialectOptions: {
      dateStrings: true,
      typeCast(field, next) {
        // for reading from database
        if (field.type === 'DATETIME') {
          return field.string();
        }
        return next();
      },
    },
  };
  // 跨域
  config.security = {
    csrf: {
      enable: false, // 前后端分离，post请求不方便携带_csrf
      ignoreJSON: true,
    },
    domainWhiteList: [ '*' ],
  };

  config.cors = {
    origin: '*',
    allowMethods: 'GET,OPTIONS,HEAD,PUT,POST,DELETE,PATCH',
  };

  // 验证白名单
  // config.auth = {
  //   ignore: [ '/login' ],
  // };

  return {
    ...config,
    ...userConfig,
  };
};
